<template>
	<view class="tab">
		<scroll-view scroll-x="true" class="tab-scroll">
			<view class="tab-scroll__box">
				<view class="tab-scroll__item" 
					v-for="(item,index) in list" 
					:key="index"
					@click="clickTab(item,index)"
					:class="{active:activeIndex === index}"
				>
					{{item.name}} 
				</view>
			</view>
		</scroll-view>
		<view class="tab-icon" @click="open">
			<text class="iconfont icon-fabu" style="size: 16px;"></text>
		</view>
	</view>
</template>

<script>
	export default {
		name:"tab",
		props:{
			list:{
				type:Array
			},
			tabIndex:{
				type:Number,
				default: 0 
			}
		},
		data() {
			return {
				activeIndex: 0
			}
		},
		methods:{
			clickTab(item,index) {
				console.log(item,index);
				this.activeIndex = index 
				this.$emit('tabs',{
					data:item,
					index:index
				})
			},
			open() {
				uni.navigateTo({
					url:"/pages/home-label/home-label"
				})
			}
		},
		watch:{
			tabIndex(newValue,oldValue) {
				console.log(newValue,oldValue);
			}
		}
	}
</script>

<style lang="scss">
	@import '../../common/css/icons.css';
	.tab{
		display: flex;
		background-color: #FFFFFF;
		border-bottom: #f5f5f5 1px solid;
		width: 100%;
		box-sizing: border-box;
		.tab-scroll {
			flex: 1;
			overflow: hidden;
			box-sizing: border-box;
			.tab-scroll__box {
				display: flex;
				height: 45px;
				align-items: center;
				flex-wrap: nowrap;
				box-sizing: border-box;
				.tab-scroll__item {
					flex-shrink: 0;
					padding: 0 10px;
					color: #333;
					font-size: 14px;
					&.active {
						color: $yk-base-color;
					}
				}
			}
		}
		
		.tab-icon {
			display: flex;
			position: relative;
			justify-content: center;
			align-items: center;
			width: 45px;
			&::after{
				content: '';
				position: absolute;
				top: 12px;
				bottom: 12px;
				left: 0;
				width: 1px;
				background-color: #ddd;
			}
			
		}
	}
</style>
